package servlet;

import entity.Powerbattery;
import service.PowerbatteryService;
import service.impl.PowerbatteryServletImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/powerbatteryUpdate")
public class powerbatteryUpdate extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PowerbatteryService service = new PowerbatteryServletImpl();
        String opr = request.getParameter("opr");
        if ("updateSet".equals(opr)){
            Powerbattery  powerbattery = new Powerbattery();
            powerbattery.setId(Integer.parseInt(request.getParameter("id")));
            powerbattery.setCarName(request.getParameter("car"));
            powerbattery.setCityName(request.getParameter("city"));
            powerbattery.setUserName(request.getParameter("user"));
            powerbattery.setTime(request.getParameter("time"));
            powerbattery.setPressureValue(Integer.parseInt(request.getParameter("pre")));
            PrintWriter out = response.getWriter();
            out.print(service.selectUpdate(powerbattery));
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
